$(function () {
    /*首页焦点图*/
    if ($("#slide").length) {
        var iSlideLiLength = $("#slide>ul>li").length,
			iSlideLiWidth = $("#slide>ul>li").width(),
			iSlideUlWidth = iSlideLiWidth * iSlideLiLength * 2,
			iSlideNumber = 0;
        $("#slide>ul").width(iSlideUlWidth);
        $("#slide>ul").append($("#slide>ul").html());
        function fnSlideNext() {
            if (!($("#slide>ul")).is(":animated")) {
                if (iSlideNumber >= iSlideLiLength) {
                    $("#slide>ul").css({ "marginLeft": "0" });
                    iSlideNumber = 0;
                }
                $("#slide>ul").animate({ "marginLeft": "-=980" }, 1000, function () {
                    iSlideNumber++;
                });
            }
        }
        function fnSlideBack() {
            if (!($("#slide>ul")).is(":animated")) {
                if (iSlideNumber <= 0) {
                    $("#slide>ul").css({ "marginLeft": -iSlideLiWidth * iSlideLiLength });
                    iSlideNumber = iSlideLiLength;
                }
                $("#slide>ul").animate({ "marginLeft": "+=980" }, 1000, function () {
                    iSlideNumber--;
                });
            }
        }
        $("#slideBack").click(fnSlideBack);
        $("#slideNext").click(fnSlideNext);
        setInterval(fnSlideNext, 5000);
    }
    /*首页学员滚动*/
    if ($("#enrollGd").length) {
        var iEnrollConHeight = $("#enrollGd>ul").height(),
			iEnrollConTime,
			iEnrollConSpeed = 50;
        $("#enrollGd>ul").append($("#enrollGd>ul").html());
        function fnEnrollConGd() {
            if (parseInt($("#enrollGd>ul").css("margin-top")) > -iEnrollConHeight) {
                $("#enrollGd>ul").css("margin-top", "-=1")
            } else {
                $("#enrollGd>ul").css("margin-top", "0")
            }
        }
        iEnrollConTime = setInterval(fnEnrollConGd, iEnrollConSpeed);
        $("#enrollGd>ul").hover(function () {
            clearTimeout(iEnrollConTime)
        }, function () {
            iEnrollConTime = setInterval(fnEnrollConGd, iEnrollConSpeed);
        })
    }
    /*学校选择*/
    if ($("#schoolGdd").length) {
        $('#schoolGdd').kxbdSuperMarquee({
            distance: 57,
            time: 3,
            direction: 'up',
            isAuto: false,
            btnGo: { up: '#schoolGddBack', down: '#schoolGddNext' }
        });
        $.tab({
            oTab: "#schoolGdd ul", 				//tab选项卡的容器（父级）
            sTabChildren: "li", 			//tab选项卡
            oTabMain: "#xx", 				//tab内容区的容器（父级）
            sTabMainChildren: "dd", 		//tab内容区
            sEarliest: false, 			//是否执行初始化显示
            sClass: "current", 			//选中样式
            sEvent: "click", 				//tab选项卡切换的触发事件
            fnAdditional: function () {
                var o = this;
                $(o.oTab).children(o.sTabChildren).bind(o.sEvent, function () {
                    var _index = $(this).index(),
						_length = $(o.oTab).children(o.sTabChildren).length / 2;
                    if (_length > 8) {
                        if (_index < _length) {
                            $(o.oTab).children(o.sTabChildren).eq(_index + _length).addClass("current");
                        } else {
                            $(o.oTab).children(o.sTabChildren).eq(_index - _length).addClass("current");
                        }
                    }
                });
            }
        });
    }
    /*首页自考院校滚动*/
    if ($("#schoolGd").length) {
        $('#schoolGd').kxbdSuperMarquee({
            distance: 166,
            time: 3,
            direction: 'left',
            btnGo: { left: '#schoolGdNext', right: '#schoolGdBack' }
        });
    }
    /*首页证书展示滚动*/
    if ($("#certificateGd").length) {
        $('#certificateGd').kxbdSuperMarquee({
            distance: 248,
            time: 5,
            direction: 'left',
            btnGo: { left: '#certificateGdNext', right: '#certificateGdBack' }
        });
    }
    /*首页技能考证滚动*/
    if ($("#examGd").length) {
        $('#examGd').kxbdSuperMarquee({
            distance: 62,
            time: 3,
            direction: 'up',
            btnGo: { up: '#examGdBack', down: '#examGdNext' }
        });
    }


    if ($("#newsTab").length) {
        $.tab({
            oTab: "#newsTab .tab", 				//tab选项卡的容器（父级）
            sTabChildren: "a", 			//tab选项卡
            oTabMain: "#newsTab", 		//tab内容区的容器（父级）
            sTabMainChildren: "dl", 		//tab内容区
            sClass: "current", 			//选中样式
            sEvent: "click", 				//tab选项卡切换的触发事件
            sEarliest: true, 				//是否执行初始化显示
            fnAdditional: function () {
                $(".tab a").click(function () {
                    var typeid = $(this).attr("typeid");
                    var _ajaxUrl = "tools/ajax.aspx";
                    $.ajax({
                        url: _ajaxUrl,
                        type: "get",
                        dataType: "json",
                        data: "action=getpt&typeid=" + typeid + "&t=" + new Date(),
                        success: function (d) {
                            if (d.RScode == 0) { $("#MenuCon").html("暂无记录！"); return; }
                            else {
                                var items = d.RSitem; var temp = "";
                                if (items.length > 9) {
                                    temp = "<dt><ul>";
                                    for (var i = 0; i < 9; i++) {
                                        temp += "<li><a href=\"educationDetails.aspx?id=" + items[i]._i + "\" title=\"" + items[i]._t + "\">" + items[i]._t + "</a><span>" + items[i]._time + "</span></li> ";
                                    }
                                    temp += "</ul></dt>";
                                    temp += "<dd><ul>";
                                    for (var j = 9; j < items.length; j++) {
                                        if (j > 17) break;
                                        temp += "<li><a href=\"educationDetails.aspx?id=" + items[j]._i + "\" title=\"" + items[j]._t + "\">" + items[j]._t + "</a><span>" + items[j]._time + "</span></li> ";
                                    }
                                    temp += "</ul></dd>";
                                } else {
                                    temp = "<dt><ul>";
                                    for (var i = 0; i < items.length; i++) {
                                        temp += "<li><a href=\"educationDetails.aspx?id=" + items[i]._i + "\" title=\"" + items[i]._t + "\">" + items[i]._t + "</a><span>" + items[i]._time + "</span></li> ";
                                    }
                                    temp += "</ul></dt>";
                                }

                                $("#MenuCon").html(temp);
                            }
                        }
                    });
                });
                $(".tab a:eq(0)").click();
            }
        });
    }
});